use esp_hal::gpio::{Output, AnyPin};

pub struct Lights<'a> {
    leds: [Output<'a, AnyPin>; 8],
    states: [bool; 8],
}

impl <'a> Lights<'a> {
    pub fn new(
        led1: Output<'a, AnyPin>,
        led2: Output<'a, AnyPin>,
        led3: Output<'a, AnyPin>,
        led4: Output<'a, AnyPin>,
        led5: Output<'a, AnyPin>,
        led6: Output<'a, AnyPin>,
        led7: Output<'a, AnyPin>,
        led8: Output<'a, AnyPin>,
    ) -> Self {
        Self {
            leds: [led1, led2, led3, led4, led5, led6, led7, led8],
            states: [false; 8],
        }
    }

    // TODO: Implement methods to toggle
    pub fn toggle(&mut self, index: usize) {
        if index < 8 {
            self.states[index] = !self.states[index];
            if self.states[index] {
                self.leds[index].set_high();
            } else {
                self.leds[index].set_low();
            }
        }
    }

    // TODO: Get state of each LED
    pub fn get_state(&self, index: usize) -> bool {
        self.states[index]
    }

    // TODO: Turn on all LEDs
    pub fn all_off(&mut self) {
        for (i, led) in self.leds.iter_mut().enumerate() {
            led.set_low();
            self.states[i] = false;
        }
    }
}